# 线性回归
from sklearn.linear_model import LinearRegression

def load_data(file_name):
    data_train = []
    f = open(file_name)
    for line in f.readlines():
        lines = line.strip().split()
        data_tmp = []
        for x in lines:
            data_tmp.append(float(x))
        data_train.append(data_tmp)
    f.close()
    return data_train


def multiple_regression(data_train, sample_data, test_data):
    linreg = LinearRegression()
    linreg.fit(sample_data, data_train)
    x_test = load_data(test_data)
    y_pred = linreg.predict(x_test)
    return y_pred


if __name__ == "__main__":
    # 1、导入数据
    data_train = load_data("resultData1578031827202.txt")
    # 3、获取样本数据
    sample_data = load_data("sampleData1578031827202.txt")
    test_data = "testData1578031827202.txt"
    # 4、对样本进行预测
    result = multiple_regression(data_train, sample_data, test_data)
    print(str(result[0][0]))
